﻿/**
 * ...
 * @author waneck
 */

package asc.enums;

enum SharedObjectChange 
{

	/**
	 * These properties can be received either for proxied than with owner
	 */
	SOChange(name:String, oldValue:String);
	SODelete(name:String, ?oldValue:String); //proxied won't receive any oldValue
	
	/**
	 * These can only be received by the proxy
	 */
	SOSuccess(name:String); //A server change of the shared object was accepted. 
	SOReject(name:String, oldValue:String); //A server change of the shared object was rejected. The value on the remote instance was not changed.
	SOClear(name:String);	//All the properties of a shared object are deleted. 
							//This can happen when the server’s shared object is out of sync with the master shared
							//object or when the persistent shared object migrates from one instance to another. 
							//This event is typically followed by a change message to restore all of the server’s 
							//shared object properties.
	
}

class SharedObjectChangeTranslator
{
	public static function translate(infoObject: { code:String, name:String, oldValue:String } ):SharedObjectChange
	{
		return switch (infoObject.code)
		{
			case "success":
				SOSuccess(infoObject.name);
			case "change":
				SOChange(infoObject.name, infoObject.oldValue);
			case "reject":
				SOReject(infoObject.name, infoObject.oldValue);
			case "delete":
				SODelete(infoObject.name, infoObject.oldValue);
			case "clear":
				SOClear(infoObject.name);
		}
	}
}